package com.nhimeye.admin.ui;

import java.util.HashSet;

import org.springframework.beans.factory.annotation.Autowired;

import com.nhimeye.admin.app.AbstractEntityView;
import com.nhimeye.admin.app.EntityEditor;
import com.nhimeye.admin.app.EntityProviderUtil;
import com.nhimeye.admin.app.H1;
import com.nhimeye.domain.ContentVersion;
import com.nhimeye.domain.Item;
import com.nhimeye.service.ItemService;
import com.vaadin.addon.jpacontainer.EntityItem;
import com.vaadin.addon.jpacontainer.JPAContainer;
import com.vaadin.data.Container;
import com.vaadin.spring.roo.addon.annotations.RooVaadinEntityView;
import com.vaadin.ui.Button;
import com.vaadin.ui.Table;


public class ItemView extends AbstractEntityView<com.nhimeye.domain.Item> {

	@Autowired
	ItemService itemService;
	
	private JPAContainer<Item> tableContainer;

    @Override
    protected void configureTable(Table table) {
        table.setContainerDataSource(getTableContainer());
        table.setVisibleColumns(getTableColumns());

       
    }

	@Override
	protected HashSet<String> getIgnoreTableColumns() {
		return new HashSet<String>();
	}

	@Override
	protected Class<? extends com.nhimeye.domain.Item> getEntityClass() {
		 return com.nhimeye.domain.Item.class;
	}

	@Override
	protected String getEntityName() {
		return "Item";
	}

	@Override
	public boolean isCreateAllowed() {
		 return true;
	}

	@Override
	protected boolean isUpdateAllowed() {
		 return true;
	}

	@Override
	protected boolean isDeleteAllowed() {
		 return true;
	}

	@Override
	protected boolean isNewEntity(com.nhimeye.domain.Item entity) {
		return (entity != null && getIdForEntity(entity) == null);
	}

	@Override
	protected void deleteEntity(com.nhimeye.domain.Item entity) {
		if (entity != null) {
			 itemService.deleteItem(entity);
	        
		}
	}

	@Override
	protected com.nhimeye.domain.Item saveEntity(com.nhimeye.domain.Item entity) {
		if (entity == null) {
            return null;
        }
         itemService.saveItem(entity);
         return entity;
	}

	@Override
	public Object getIdProperty() {
		return "id";
	}

	@Override
	public Object getVersionProperty() {
		return "version";
	}

	@Override
	protected Container getTableContainer() {
		if (tableContainer == null) {
            JPAContainer<Item> container = new JPAContainer<Item>(Item.class);
            container.setEntityProvider(EntityProviderUtil.get().getEntityProvider(Item.class));
            tableContainer = container;
        }
        return tableContainer;
	}

	@Override
	protected com.vaadin.data.Item getItemForEntity(Item entity) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected Item getEntityForItem(com.vaadin.data.Item item) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object getIdForEntity(Item entity) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected Item createEntityInstance() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected EntityEditor<Item> createForm() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void configureButton(Button b) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void configureCaption(H1 title) {
		// TODO Auto-generated method stub
		
	}

}
